
/*
 观察者模式，当有人请求的时候，就会通知mtMock对象，
 遍历该对象里的通过mtMock.mock的方式注册的接口，
*/
let MTMock = {
	mock: function(url, callBack){
		let params = {}
		// 对url进行分割
		let splitUrl = url.split('?')
		let targetUrl = ''
		splitUrl.forEach((item,index) => {
			if (index === 0) {
				targetUrl = item
			} else {
				let keyValues = item.split('=')
				let key = keyValues[0]
				let value = keyValues[1]
				params[key] = value
			}
		})
		console.log('targetUrl', targetUrl)
		// 对config进行判断处理
		this.watchers[targetUrl] = {
			start:function(_params){
				let p = {..._params, ...this.params}
				return callBack(p)
			},
			params
		}
	},
	watchers:  {},
	notify(url, params) {
		return {data:this.watchers[url].start(params)}
	}
}

export default MTMock